package com.fhb.demo.myapp.youmeng.ui.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.fhb.demo.myapp.youmeng.YMApplication;
import com.umeng.message.PushAgent;


/**
 * Created by Administrator on 2018/6/1.
 */

public abstract class BaseActivity extends AppCompatActivity {
    private String TAG = this.getClass().getSimpleName();
    protected PushAgent mPushAgent = null;
    protected String DIVER_TOKEN = null;
    private YMPlushReceiver mReceiver = null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        ymReceiver();
//        mPushAgent = PushAgent.getInstance(this);
//        mPushAgent.onAppStart();

    }

    private void ymReceiver() {
        mReceiver = new YMPlushReceiver();
        IntentFilter mFilter = new IntentFilter();
        mFilter.addAction(YMApplication.YMPLUSH_RECEIVERS_ACTION);
        registerReceiver(mReceiver, mFilter);

    }

    private class YMPlushReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            initData(intent);
        }
    }

    private void initData(Intent intent) {
        String flag = intent.getStringExtra("flag");
        Log.e(TAG, flag);
        if (flag.trim().equals("success")) {
            DIVER_TOKEN = mPushAgent.getRegistrationId();
        } else {
            DIVER_TOKEN = null;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mReceiver != null)
            unregisterReceiver(mReceiver);
    }
}
